package cn.tedu.map;

import java.util.*;

/**
 * @author ：Dsi
 *
 * @date ：2021/11/18 16:10
 * Describe ：该类用于测试Map接口
 */
public class TestMap {

    public static void main(String[] args) {
        /*Map中的数据要符合KV映射关系
         * 注意：需要同时指定K，V的数据类型
         * */
        Map<Integer, String> m = new HashMap<>();
        m.put(9527, "狐狸精");
        m.put(9534, "白骨精");
        m.put(9537, "黑熊精");
        m.put(9557, "蝴蝶精");
        System.out.println(m);
        m.put(9527, "鸡精");
        //m.clear();
        System.out.println(m);
        System.out.println(m.isEmpty());
        System.out.println(m.size());
        System.out.println(m.containsKey(9527));
        System.out.println(m.containsValue("狐狸精"));
        System.out.println(m.get(9527));
        System.out.println(m.entrySet());
        Collection<String> values = m.values();

        Set<Integer> set = m.keySet();//转成set集合
        Iterator<Integer> i1 = set.iterator();//获取set迭代器
        while (i1.hasNext()){
            int a=i1.next();
            System.out.println(a);
            System.out.println(m.get(a));
        }

        for (Integer a:set
             ) {
            System.out.print(a+"=");
            System.out.println(m.get(a));
        }
        Set<Map.Entry<Integer, String>> entries = m.entrySet();
        System.out.println(entries);
        Set a=m.entrySet();
        System.out.println(a);
    }
}
